package com.czc.mvc.config;

import com.czc.entity.Admin;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.util.List;


/*
    考虑到security User对象中仅仅包含帐号和密码,为了能够获取到原始的Admin对象
    专门创建了这个类对User 类进行扩展
 */
public class SecurityAdmin extends User {

    private static final long serialVersionUID=1L;

    //原始的Admin对象,包含Admin对象的全部属性
    private Admin originalAdmin;

    public SecurityAdmin(
            //传入原始的Admin对象
            Admin originalAdmin,

            //创建角色,权限的集合
            List<GrantedAuthority> authorityList){

        //调用父类构造器
        super(originalAdmin.getLoginAcct(),originalAdmin.getUserPswd(),authorityList);

        this.originalAdmin=originalAdmin;

        //将原始Admin对象中的密码擦除
        this.originalAdmin.setUserPswd(null);
    }

    public Admin getoriginalAdmin(){
        return originalAdmin;
    }
}
